package mamikeji.liaowa.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

import mamikeji.liaowa.application.MyApplication;


/**
 * 保存临时文件SP
 */
public class ForPreference
{
    private static String share_name = "mamikeji_share";

    public static SharedPreferences getPreference()
    {
        return MyApplication.getContext().getSharedPreferences(share_name, Context.MODE_PRIVATE);
    }

    public static void putString(String key, String value)
    {
        Editor editor = getPreference().edit();

        editor.putString(key, value);
        editor.commit();
    }

    public static String getString(String key)
    {
        return getPreference().getString(key, "");
    }

    public static void putInt(String key, int value)
    {
        Editor editor = getPreference().edit();

        editor.putInt(key, value);
        editor.commit();
    }

    public static int getInt(String key)
    {
        return getPreference().getInt(key, 0);
    }

    public static void putBoolean(String key, boolean value)
    {
        Editor editor = getPreference().edit();

        editor.putBoolean(key, value);
        editor.commit();
    }

    public static boolean getBoolean(String key)
    {
        return getPreference().getBoolean(key, false);
    }

    public static void putLong(String key, long value)
    {
        Editor editor = getPreference().edit();

        editor.putLong(key, value);
        editor.commit();
    }

    public static void clearDate()
    {
        Editor editor = getPreference().edit();
        editor.remove(ForContents.USER_COUNT);//清除孩子数量
        editor.remove(ForContents.USER_CODE);//清除用户code
        editor.remove(ForContents.USER_PHONE);//清除手机号
        editor.remove(ForContents.USER_NAME);//清除用户名称
        editor.remove(ForContents.USER_SEX);//清除用户性别
        editor.remove(ForContents.USER_BIRTHDAY);//清除用户生日
        editor.remove(ForContents.USER_ADDRESS);//清除用户地址
        editor.remove(ForContents.USER_HEADERURL);//清除用户头像
        editor.remove(ForContents.USER_YUNYU);//清除用户孕育状态
        editor.remove(ForContents.USER_DESCRIBE);//用户简介
        editor.remove(ForContents.USER_COLLECTION);//用户收藏数量
        editor.remove(ForContents.USER_every_diary);//用户每日随笔数量
        editor.remove(ForContents.USER_today_diary);//用户今日随笔数量
        editor.remove(ForContents.USER_activationcode);//用户邀请码

        editor.remove(ForContents.WA_DEFAULT_ID);//用户邀请码
        editor.remove(ForContents.WA_ID);//用户邀请码
        editor.remove(ForContents.WA_nickname);//用户邀请码
        editor.remove(ForContents.WA_DAY);//用户邀请码
        editor.remove(ForContents.WA_STATIC);//用户邀请码
        editor.remove(ForContents.WA_describe);//用户邀请码
        editor.remove(ForContents.WA_HeaderImg);//用户邀请码
        editor.remove(ForContents.WA_heigh);//用户邀请码
        editor.remove(ForContents.WA_weight);//用户邀请码

        editor.commit();
    }

    public static Long getLong(String key)
    {
        return getPreference().getLong(key, 0);
    }
}
